/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.sys.web.user;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.sys.entity.user.HkAdvRewardLog;
import com.thinkgem.jeesite.modules.hk.sys.service.user.HkAdvRewardLogService;

/**
 * 用户打赏日志Controller
 * @author 罗天文
 * @version 2018-05-08
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/user/hkAdvRewardLog")
public class HkAdvRewardLogController extends BaseController {

	@Autowired
	private HkAdvRewardLogService hkAdvRewardLogService;
	
	@ModelAttribute
	public HkAdvRewardLog get(@RequestParam(required=false) String id) {
		HkAdvRewardLog entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkAdvRewardLogService.get(id);
		}
		if (entity == null){
			entity = new HkAdvRewardLog();
		}
		return entity;
	}
	
	@RequiresPermissions("sys:user:hkAdvRewardLog:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkAdvRewardLog hkAdvRewardLog, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkAdvRewardLog> page = hkAdvRewardLogService.findPage(new Page<HkAdvRewardLog>(request, response), hkAdvRewardLog); 
		model.addAttribute("page", page);
		return "hk/sys/user/hkAdvRewardLogList";
	}

	@RequiresPermissions("sys:user:hkAdvRewardLog:view")
	@RequestMapping(value = "form")
	public String form(HkAdvRewardLog hkAdvRewardLog, Model model) {
		model.addAttribute("hkAdvRewardLog", hkAdvRewardLog);
		return "hk/sys/user/hkAdvRewardLogForm";
	}

	@RequiresPermissions("sys:user:hkAdvRewardLog:edit")
	@RequestMapping(value = "save")
	public String save(HkAdvRewardLog hkAdvRewardLog, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkAdvRewardLog)){
			return form(hkAdvRewardLog, model);
		}
		hkAdvRewardLogService.save(hkAdvRewardLog);
		addMessage(redirectAttributes, "保存用户打赏日志成功");
		return "redirect:"+Global.getAdminPath()+"/sys/user/hkAdvRewardLog/?repage";
	}
	
	@RequiresPermissions("sys:user:hkAdvRewardLog:edit")
	@RequestMapping(value = "delete")
	public String delete(HkAdvRewardLog hkAdvRewardLog, RedirectAttributes redirectAttributes) {
		hkAdvRewardLogService.delete(hkAdvRewardLog);
		addMessage(redirectAttributes, "删除用户打赏日志成功");
		return "redirect:"+Global.getAdminPath()+"/sys/user/hkAdvRewardLog/?repage";
	}

}